package com.sskj.quantization.util;

import android.app.Activity;
import android.support.design.widget.BottomSheetDialog;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.sskj.common.base.App;
import com.sskj.common.util.ClickUtil;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.util.CoinUtil;
import com.sskj.quantization.R;

public class TipQuanUtil {
    public static BottomSheetDialog showBuy(Activity activity, String usdt, String usdtRepre, OnInput onInput) {
        BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(activity);
        View rootView = LayoutInflater.from(activity).inflate(R.layout.quan_bottom_sheet_buy, null, false);
        TextView tvUSDT = rootView.findViewById(R.id.tvUSDT);
        TextView tvUSDTRep = rootView.findViewById(R.id.tvUSDTRep);
        tvUSDT.setText(String.format("%s USD", CoinUtil.keepUSDT(usdt)));
        tvUSDTRep.setText(String.format("%s GRCT", CoinUtil.keepCoin(usdtRepre)));
        EditText etPwd = rootView.findViewById(R.id.etPwd);
        Button btBuy = rootView.findViewById(R.id.btBuy);
        ClickUtil.click(btBuy, () -> {
            if (TextUtils.isEmpty(etPwd.getText())) {
                ToastUtil.showShort(App.INSTANCE.getString(R.string.quan_tipQuanUtil1_h));
                return;
            }
            if (onInput != null) {
                onInput.onInput(etPwd.getText().toString());
            }
        });
        bottomSheetDialog.setContentView(rootView);
        bottomSheetDialog.setCancelable(true);
        bottomSheetDialog.setCanceledOnTouchOutside(true);
        return bottomSheetDialog;
    }

    public static BottomSheetDialog showCash(Activity activity, String usdt, String usdtRepre, String rate, OnInput onInput) {
        BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(activity);
        View rootView = LayoutInflater.from(activity).inflate(R.layout.quan_bottom_sheet_cash, null, false);
        TextView tvUSDT = rootView.findViewById(R.id.tvUSDT);
        TextView tvUSDTRep = rootView.findViewById(R.id.tvUSDTRep);
        TextView tvRate = rootView.findViewById(R.id.tvRate);
        tvUSDT.setText(String.format("%s USD", CoinUtil.keepUSDT(usdt)));
        tvUSDTRep.setText(String.format("%s GRCT", CoinUtil.keepCoin(usdtRepre)));
        tvRate.setText(String.format("%s GRCT", CoinUtil.keepCoin(rate)));
        EditText etPwd = rootView.findViewById(R.id.etPwd);
        Button btBuy = rootView.findViewById(R.id.btBuy);
        ClickUtil.click(btBuy, () -> {
            if (TextUtils.isEmpty(etPwd.getText())) {
                ToastUtil.showShort(App.INSTANCE.getString(R.string.quan_tipQuanUtil1_h));
                return;
            }
            if (onInput != null) {
                onInput.onInput(etPwd.getText().toString());
            }
        });
        bottomSheetDialog.setContentView(rootView);
        bottomSheetDialog.setCancelable(true);
        bottomSheetDialog.setCanceledOnTouchOutside(true);
        return bottomSheetDialog;
    }

    public interface OnInput {
        void onInput(String... input);
    }
}
